<?php
/**
* @author Amasty Team
* @copyright Amasty
* @package Amasty_Flags
*/
class Amasty_Flags_Block_Adminhtml_Sales_Order_Grid_Flag extends Mage_Adminhtml_Block_Template
{
    protected $_order = null;
    
    protected function _prepareLayout()
    {
        parent::_prepareLayout();
        $this->setTemplate('amflags/flag.phtml');
        return $this;
    }
    
    public function setOrder($order)
    {
        $this->_order = $order;
        return $this;
    }
    
    public function getOrder()
    {
        return $this->_order;
    }
    
    public function getCurrentFlag()
    {
        $orderFlag = Mage::getModel('amflags/order_flag')->load($this->getOrder()->getId(), 'order_id');
        $flag = Mage::getModel('amflags/flag')->load($orderFlag->getFlagId());
        if (!$flag->getId())
        {
            return null;
        }
        if ($orderFlag->getComment())
        {
            // if specific comment was set to the order flag, replacing flag comment with order comment.
            $flag->setComment($orderFlag->getComment());
        }
        return $flag;
    }
    
    public function getEmptyFlagUrl()
    {
        return $this->getSkinUrl('images/amflags/empty.gif');
    }
    
    public function getDownArrowUrl()
    {
        return $this->getSkinUrl('images/amflags/arrow.gif');
    }
    
    public function getFlagCollection()
    {
        if (!Mage::registry('amflags_flag_collection'))
        {
            $flagCollection = Mage::getModel('amflags/flag')->getCollection();
            Mage::register('amflags_flag_collection', $flagCollection, true);
        }
        return Mage::registry('amflags_flag_collection');
    }
    
    public function getSetFlagUrl()
    {
        return $this->getUrl('amflags/adminhtml_flag/setFlag');
    }
}